var loginVue = new Vue({
	el:"#app",
	data:{
		btn_text:"发送验证码",
		tel:"",
		code:"",
		shareUserId:""
	},
	methods:{
		sendCode:function(){
			if(this.btn_text!="发送验证码"){
				return;
			}
			if(!this.tel){
				return;
			}
			
			if(!(/^1(3|4|5|7|8|9)\d{9}$/.test(this.tel))){ 
				wx.showToast({title:"手机号码有误!"});
				return;
			}
			wx.showLoading({title:"加载中..."});
			this.$http.post(baseUrl+"code/send",{
				mobile:this.tel
			}).then(function(e){
				var d = e.data;
				if(d.success){
					this.second();
					wx.hideLoading(), wx.showToast({
						title: "发送成功!注意查收",
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				}else{
					wx.hideLoading(), wx.showToast({
						title: d.description,
						icon: "none",
						duration: 2e3,
						mask: !0
					});
				}
			}).catch(function(e){
				wx.hideLoading(), wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			});
		},
		second:function(){
			var i = 60;
			var t = this;
			var interval = setInterval(function(){
				if(i==0){
					clearInterval(interval);
					t.btn_text="发送验证码";
					return;
				}
				t.btn_text = i-- + '秒后可重新发送';
			},1000)
		},
		userLogin:function(){
			if(!this.tel){
				return;
			}
			if(this.shareUserId==""){
				wx.showToast({title:"没有分享人，无法领取!"});
				return;
			}
			if(!(/^1(3|4|5|7|8)\d{9}$/.test(this.tel))){ 
				wx.showToast({title:"手机号码有误!"});
				return;
			}
			if(!this.code){
				wx.showToast({title:"请输入验证码!"});
				return;
			}
			if(this.code.length!=6){
				wx.showToast({title:"请正确输入验证码!"});
				return;
			}
			wx.showLoading({title:"加载中..."});
			this.$http.post(baseUrl+"app/login",{
				tel:this.tel,
				code:sha256_digest(this.code),
				shareUserId:this.shareUserId
			}).then(function(e){
				wx.hideLoading();
				var d =e.data;
				if(!d.success){
					wx.showToast({
						title: d.description
					});
					localStorage.removeItem("open_id");
					localStorage.removeItem("user_data");
					return;
				}else{
					$(document).dialog({
						type:'confirm',
						titleText:"领取积分成功!",
						position:'center',
						content:"亲！恭喜您领取积分成功！立即下载app使用吧！",
						buttonTextConfirm:"要得",
						buttonTextCancel:"算了",
						onClickConfirmBtn:function(){
							window.location.href="https://app.meijiangzi.com/static/mjzapp.html";
						},
					});
				}
			}).catch(function(e){
				wx.hideLoading(), wx.showToast({
					title: "网络错误，请稍后重试",
					icon: "none",
					duration: 2e3,
					mask: !0
				});
			})
			
		}
	},
	created:function(){
		this.shareUserId=URLParam.get("shareUserId");
	}
});